<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import insurance from '@/api/admin/insurance'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (record, newValue, numberName) => {
  insurance.numberOperation({ id: record.id, numberName, numberValue: newValue }).then( res => {
    if (res.success) {
      Message.success(res.message)
      record[numberName] = newValue
    }
  }).catch( e => { console.log(e) } )
}


const switchStatus = (record, statusValue, statusName) => {
  insurance.changeStatus({ id: record.id, statusName, statusValue }).then( res => {
    if (res.success) {
      Message.success(res.message)
      record[statusName] = statusValue
    }
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'insurance',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: insurance.getList,
  // recycleApi: insurance.getRecycleList,
  requestParams: { orderBy: ['id'], orderType: 'desc', 'car_id': 0 },
  add: {
    show: true,
    api: insurance.save,
    auth: ['admin:insurance:save']
  },
  edit: {
    show: true,
    api: insurance.update,
    auth: ['admin:insurance:update']
  },
  delete: {
    show: true,
    api: insurance.deletes,
    auth: ['admin:insurance:delete'],
    realApi: insurance.realDeletes,
    realAuth: ['admin:insurance:realDeletes']
  },
  /*recovery: {
    show: true,
    api: insurance.recoverys,
    auth: ['admin:insurance:recovery']
  },
  import: {
    show: true,
    url: 'admin/insurance/import',
    templateUrl: 'admin/insurance/downloadTemplate',
    auth: ['admin:insurance:import']
  },
  export: {
    show: true,
    url: 'admin/insurance/export',
    auth: ['admin:insurance:export']
  }*/
})

const columns = reactive([
  {
    title: "",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入"
    }
  },
  {
    title: "保险等级",
    dataIndex: "level",
    formType: "select",
    search: true,
    commonRules: {
      required: true,
      message: "请输入保险等级"
    },
    multiple: false,
    dict: {
      data: [
        {
          label: "1级",
          value: "1"
        },
        {
          label: "2级",
          value: "2"
        },
        {
          label: "3级",
          value: "3"
        }
      ],
      translation: true
    }
  },
  {
    title: "名称",
    dataIndex: "name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入名称"
    }
  },
  {
    title: "车损保障",
    dataIndex: "car_damage",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入车损保障"
    }
  },
  {
    title: "车损保障副描述",
    dataIndex: "car_damage_sub",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入车损保障副描述"
    }
  },
  {
    title: "三者保障",
    dataIndex: "tripartite",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入三者保障"
    }
  },
  {
    title: "乘客保障",
    dataIndex: "passenger",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入乘客保障"
    }
  },
  {
    title: "免折旧费",
    dataIndex: "free_depreciation",
    formType: "select",
    commonRules: {
      required: true,
      message: "请输入免折旧费"
    },
    dict: {
      data: [
        {
          label: "否",
          value: "0"
        },
        {
          label: "是",
          value: "1"
        }
      ],
      translation: true
    }
  },
  {
    title: "无需垫付",
    dataIndex: "no_need_advance",
    formType: "select",
    commonRules: {
      required: true,
      message: "请输入无需垫付"
    },
    dict: {
      data: [
        {
          label: "否",
          value: "0"
        },
        {
          label: "是",
          value: "1"
        }
      ],
      translation: true
    }
  },
  {
    title: "免停运费",
    dataIndex: "free_outage",
    formType: "select",
    commonRules: {
      required: true,
      message: "请输入免停运费"
    },
    dict: {
      data: [
        {
          label: "否",
          value: "0"
        },
        {
          label: "是",
          value: "1"
        }
      ],
      translation: true
    }
  },
  {
    title: "原本单价(天)",
    dataIndex: "original_price",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入原本单价(天)"
    }
  },
  {
    title: "单价(天)",
    dataIndex: "price",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入单价(天)"
    }
  },
  {
    title: "详情",
    dataIndex: "detail",
    formType: "editor",
    hide: true,
    commonRules: {
      required: true,
      message: "请输入详情"
    }
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    showTime: true
  }
])
</script>
<script> export default { name: 'admin:insurance' } </script>
